/**
 ********************************************************************
 * @author roocket
 * @file    socket.h
 * @version V0.0.0
 * @date    2024/3/22
 * @brief   This file is to indicate socket functions. 
 * @attention Code file rules:
 * rule: file encoding use UTF8;
 * rule: max line length 120 characters;
 * rule: line separator \r\n;
 * rule: use clion auto code format tool.
 */

#ifndef _SOCKET_H_
#define _SOCKET_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>

/* macros for definition to socket's address and port */
#define SOCKET_SERVER_ADDRESS "127.0.0.1"
#define SOCKET_SERVER_PORT    12345
#define SOCKET_WR_BUFER_LEN   2048  /* just more than MTU */
#define SOCKET_WR_MAX_STREAM_BUFFER (1024 * 32)

/* common operations for both client and server */

int socket_client_init(const char *address, const unsigned short port);
int socket_server_init(const char *address, const unsigned short port);

int socket_get_data(int fd, void *user);

int socket_set_data(int fd, void *sent, int length);

void socket_del(int fd);

#endif /* _SOCKET_H_ */
